package test;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.renren.api.client.RenrenApiClient;
import com.renren.api.client.param.impl.AccessToken;
import com.wtb.pub.WtbBaseServlet;
import com.wtb.rr.domain.RrOauth;

@SuppressWarnings("serial")
public class StatusServlet extends WtbBaseServlet {

	@SuppressWarnings("unchecked")
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		ServletContext context;
		context = this.getServletContext();
		Map<String, RrOauth> rr_map = (Map<String, RrOauth>) context.getAttribute("rr_map");
		String status = "不用理我，我是一条API测试状态！ ！";
		Collection<RrOauth> rr_Collection = rr_map.values();
		for (Iterator iterator = rr_Collection.iterator(); iterator.hasNext();) {
			RrOauth rrOauth = (RrOauth) iterator.next();
			RenrenApiClient client = RenrenApiClient.getInstance();
			try {
				client.getStatusService().setStatus(status,
						new AccessToken(rrOauth.getAccess_token()));
			} catch (Exception e) {
				System.out.println(e.getMessage());
				request.setAttribute("errMsg", e.getMessage());
			}
		}
	}

}
